package com.app.OOS.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.app.OOS.domain.Batch_Coursewares;
import com.app.OOS.domain.Score;
import com.app.OOS.domain.User;
import com.app.OOS.domain.User_courseware_batch;
import com.app.OOS.mapper.UserMapper;



@Service
public class UserService {
	@Autowired
	UserMapper userMapper;
	//注册
	public void insertUser(int userId,String userName,String password) {
		userMapper.insertUser(userId, password, userName);
	}
	//登陆
	public User selectUser(User user) {
		User user1 = userMapper.selectUser(user);	
		return user1;
	}
	//修改密码
	public void updatePassword(User user) {
		userMapper.updatePassword(user);
	}
	
	//查询学员-批次-课件
	public List<Batch_Coursewares> selectBacthNameCoursewareName(Object object,int tmp,int limit){
		List<Batch_Coursewares> list =	userMapper.selectBacthNameCoursewareName(object,tmp,limit);
		return list;
	}
	public int tol(Object object) {
		int tol=userMapper.tol(object);
		return tol;
	}
	
	//查找视频src
	public String selectSrc(int coursewareId) {
		String src=userMapper.selectSrc(coursewareId);
		return src;
	}
	
	//查看成绩
	public List<Score> selectScore1(Object object) {
		List<Score> score=userMapper.selectScore1(object);
		return score;
	}
	
	//查询学习记录
	public List<User_courseware_batch> selectRecord(Object object){
		List<User_courseware_batch> list =userMapper.selectRecod(object);
		return list;
	}
	
	//插入记录
	public Map<String, Object> insertStudy(Object object,int coursewareId,int batchId) {
	int t=	userMapper.tol8(object, coursewareId, batchId);
	Map<String, Object> map=new HashMap<String, Object>();
	if(t==0) {
		userMapper.insertStudy(object, coursewareId, batchId);
		map.put("meaasge","0" );
	}else {
		int time=userMapper.time(object, coursewareId, batchId);
		map.put("message", "1");
		map.put("time", time);
		
	}
	return map;
	}
	
	
	
	//更新时间
	
	public void updatetime(Object object,int coursewareId,int batchId,int time) {
		userMapper.updatetime(object, coursewareId, batchId,time);
	}
	
	
	//更新状态
	public void updateState(Object object,int batchId,int coursewareId) {
		userMapper.updateState(coursewareId,batchId,coursewareId);
	}
	
	//参加考试
	public String doExamal(Object object) {
		int tol1=userMapper.tol9(object);
		int tol2=userMapper.tol10(object);
		String s=null;
		if(tol2>=0.8*tol1) {
			 s="Yes";
		}else {
			 s="No";
		}
		return s;
	}
}
